package setTest;

import listTest.Device;

import java.util.ArrayList;
import java.util.HashSet;

public class SetTest {

    public static void main(String[] args) {
        setDevice();
    }

    public static void setDevice() {
        //HashSet无序且唯一
        HashSet<Device> setTest = new HashSet<>();
        Device device = new Device();
        device.setId(1L);
        device.setName("分界线");
        device.setUserName("分界线的电脑");
        Device device2 = new Device();
        device2.setId(2L);
        device2.setName("分界线2");
        device2.setUserName("分界线的电脑2");
        setTest.add(device);
        setTest.add(device2);
        //set没有get声明了Device类型里面就只能放Device了
        HashSet<Device> setTest2 = new HashSet<>();
        for (int i = 0; i < setTest.size(); i++) {
            System.out.println(setTest.toString());
        }
        for (Device de : setTest) {
            //遍历出来就直接放到第二个set(setTest2)里面
            setTest2.add(de);
            System.out.println("设备id: " + de.getId() + ",设备名字: " + de.getName() + ",用户名: " + de.getUserName());

        }

        System.out.println("---------------------------------");
        //创建一个Device类型的ArrayList
        ArrayList<Device> list = new ArrayList<>();

        for (int i = 0; i < 20; i++) {
            list.add(device);
        }
        //遍历list
        for (Device d : list) {
            System.out.println("设备id: " + d.getId() + ",设备名字: " + d.getName() + ",用户名: " + d.getUserName());
        }
        System.out.println(list.size());

        HashSet<Device> devSet = new HashSet<>();
        //addAll添加全部 set不可以重复,这里添加进去直接去重
        devSet.addAll(list);
        //打印devSet的个数
        System.out.println(devSet.size());
        //遍历devSet
        for (Device de : devSet) {
            //遍历出来就直接放到第二个set(setTest2)里面
            System.out.println("设备id: " + de.getId() + ",设备名字: " + de.getName() + ",用户名: " + de.getUserName());

        }
    }


}
